/**
 * 
 */
package cc.rico.utils;

import org.apache.shiro.crypto.hash.Sha256Hash;

/**
 * Sha256Hash 工具类
 * @author JiWo 2016年6月22日
 *
 */
public class Sha256HashUtil {
	
	private static final Object DEFAULT_SALT = "";
	private static final int DEFAULT_HASH_ITERATIONS = 1;
	
	private Object salt = DEFAULT_SALT;
	private int hashIterations = DEFAULT_HASH_ITERATIONS;
	
	public Sha256HashUtil() {
		
	}
	
	public Sha256HashUtil(Object salt, int hashIterations) {
		this.salt = salt;
		this.hashIterations = hashIterations;
	}
	
	public String encode(Object source) {
		String hashedPasswordBase64 = new Sha256Hash(source, salt, hashIterations).toBase64();
		return hashedPasswordBase64;
	}
	
	public String encode(Object source, Object salt) {
		String hashedPasswordBase64 = new Sha256Hash(source, salt, hashIterations).toBase64();
		return hashedPasswordBase64;
	}
	
	public Object getSalt() {
		return salt;
	}

	public void setSalt(Object salt) {
		this.salt = salt;
	}

	public int getHashIterations() {
		return hashIterations;
	}

	public void setHashIterations(int hashIterations) {
		this.hashIterations = hashIterations;
	}
}
